#include <cstdio>

int main(int argc, char const *argv[]) {
    int a, b;
    while (scanf("%d%d", &a, &b) != EOF) {
        if (a == 0 && b == 0)
            break;
        int k;
        scanf("%d", &k);
        int buf_data_a[20] = {0}, buf_data_b[20] = {0};
        int size_a = 0, size_b = 0;
        int temp_a = a;
        while (temp_a != 0) {
            buf_data_a[size_a++] = temp_a % 10;
            temp_a /= 10;
        }
        int temp_b = b;
        while (temp_b != 0) {
            buf_data_b[size_b++] = temp_b % 10;
            temp_b /= 10;
        }
        bool same_k_num = true;
        for (int i = 0; i < k; i++) {
            if (buf_data_a[i] != buf_data_b[i]) {
                same_k_num = false;
                break;
            }
        }
        if (same_k_num)
            printf("-1\n");
        else
            printf("%d\n", a + b);
    }
    return 0;
}
